import 'package:flutter/cupertino.dart';
import 'package:imitatectripapp/model/home_model.dart';
import 'dart:async';
import 'dart:convert'; //模型转换需要用到这个类
import 'package:http/http.dart' as http;

const HOME_URL = 'https://www.devio.org/io/flutter_app/json/home_page.json';

// 首页大接口

class HomeDao {
  static Future<HomeModel> fetch() async {
    final response = await http.get(HOME_URL);
    if (response.statusCode == 200) {
      // 解决中文乱码
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return HomeModel.fromJson(result);
    }else{
      print('请求接口失败');

      throw Exception('请求接口失败');
    }
  }
}
